package com.qriver.session.interceptor;

import com.qriver.session.common.SsoConstant;
import com.qriver.session.utils.CookieUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Feign拦截器，主要处理Cookie数据
 */
@Configuration
public class FeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        String cookies = CookieUtils.getCookieValue(request, SsoConstant.COOKIE_USER_TICKET);
        requestTemplate.header(SsoConstant.COOKIE_USER_TICKET, cookies);

    }

}
